package com.inspectortime.webapp.inspector.fee;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.inspectortime.domain.OptionalService;
import com.inspectortime.util.SpringValidatorUtils;
import com.mkode.util.java.lang.ClassUtils;

/**
 * @author mkvalsvik
 * 
 */
public class OptionalServiceFormValidator implements Validator {
	
	public boolean supports(Class clazz) {
		return ClassUtils.isInstanceOf(clazz, OptionalService.class);
	}

	public void validate(Object obj, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title","required");
		SpringValidatorUtils.rejectIfTooLong(errors, "title", "tooLong", 50);
		SpringValidatorUtils.rejectIfZero(errors, "price", "required");
		SpringValidatorUtils.rejectIfTooLong(errors, "description", "tooLong", 255);
	}
	
}
